package cc.eddic.practice.concurrency;

import cc.eddic.practice.concurrency.impl.LogItemParserExecutorImpl;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Collection;

@Slf4j
@SpringBootApplication

public class ConcurrencyExecutorWqjApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(ConcurrencyExecutorWqjApplication.class, args);
    }

    @Override

    public void run(String... args) throws Exception {
        LogParser logParser = new LogItemParserExecutorImpl();
        long start = System.currentTimeMillis();
        if (log.isInfoEnabled()) log.info("Hello World!");
        val folderName = "C:\\Users\\huawei\\Desktop\\sony_practice\\nginx-logs";
        val logItems = logParser.parse(folderName);
        if (log.isInfoEnabled()){
            log.info("elapsed {}ms", System.currentTimeMillis() - start);
            log.info("files : {}", logItems.size());
            log.info("total log items : {}", logItems.values().stream().mapToLong(Collection::size).sum());
            log.info("valid log items : {}", logItems.values().stream().flatMap(Collection::stream).filter(LogItem::isValidRequest).count());
        }

    }
}
